<?php

namespace App\Containers\AppSection\Accreditation\Tasks;

use App\Containers\AppSection\Accreditation\Data\Repositories\AccreditationRepository;
use App\Containers\AppSection\Accreditation\Models\Accreditation;
use App\Ship\Exceptions\BadRequestException;
use App\Ship\Parents\Tasks\Task;
use Exception;

class FindAccreditationByIdTask extends Task
{

    protected AccreditationRepository $repository;

    public function __construct(
        AccreditationRepository $repository
    )
    {
        $this->repository = $repository;
    }

    public function run($id): Accreditation
    {
        try {
            return $this->repository->find($id);
        } catch (Exception $exception) {
            throw new BadRequestException();
        }
    }
}
